package test;

//利用多态给宠物喂食

public class exam04 {
    public static void main(String[] args) {
        Animal animals = new Dog(97, 50);
        animals.eat();
    }
}

abstract class Animal {
    private int health;
    private int love;

    public int getHealth() {
        return health;
    }

    public void setHealth(int health) {
        this.health = health;
    }

    public int getLove() {
        return love;
    }

    public void setLove(int love) {
        this.love = love;
    }

    public Animal(int health, int love) {
        this.health = health;
        this.love = love;
    }

    public Animal() {
    }

    public abstract void eat();
}

class Dog extends Animal {

    public Dog(int health, int love) {
        super(health, love);
    }

    public Dog() {
    }

    @Override
    public void eat() {
        int health;
        health = this.getHealth();
        if (health <= 97) {
            health += 3;
            System.out.println("吃了狗粮增加3健康值,当前健康值为:" + health);
        } else {
            health = 100;
            System.out.println("狗狗很饱了");
        }
        this.setHealth(health);
    }

}

class Penguin extends Animal {
    public Penguin(int health, int love) {
        super(health, love);
    }

    public Penguin() {
    }

    @Override
    public void eat() {
        int health;
        health = this.getHealth();
        if (health <= 95) {
            health += 5;
            System.out.println("吃了鱼增加5健康值,当前健康值为:" + health);
        } else {
            health = 100;
            System.out.println("企鹅很饱了");
        }
        this.setHealth(health);
    }
}

